# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
from scrapy.pipelines.images import ImagesPipeline
import scrapy
import os

class CardmiPipeline:
    def process_item(self, item, spider):
        return item


class ImagePipeline(ImagesPipeline):

    def get_media_requests(self, item, info):
        url = 'https://res.nba.cn/media/img/players/head/260x190/{}.png'.format(item['id'])
        print(url + '=========')
        yield scrapy.Request(url, meta={'name': item['name']})


    def file_path(self, request, response=None, info=None, *, item=None):
        return 'nba/' + request.meta['name'] + '.png'